/*
 * @Date: 2024-07-08 18:06:38
 * @LastEditors: lyx
 * @LastEditTime: 2024-07-09 15:34:09
 * @FilePath: \minute-dota2\apis\index.ts
 * @Description: 
 */

import { mockHeroList } from "./mockData";

// 重新验证
const fetchDataCacheOpts = { next: { revalidate: 86400 } };

export const getHeroList = async() =>{
  const res = await fetch('https://www.dota2.com.cn/datafeed/heroList?task=herolist',fetchDataCacheOpts);
  if (!res.ok) {
    // 由最近的 error.js 处理
    throw new Error('Failed to fetch data')
  }
  const result = await res.json();
  const {result:heroList = [],status} = result;
  return status==='success'? mockHeroList.slice(0,10) : [];
}